/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the  Eclipse Public License -v 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.eclipse.org/legal/epl-2.0/
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include "mqtt_subscribe_options.h"

namespace OHOS {
namespace PahoMqtt {
MqttSubscribeOptions::MqttSubscribeOptions() {}

void MqttSubscribeOptions::ClearTopic()
{
    topics_.clear();
}

void MqttSubscribeOptions::AddTopic(const std::string &topic, uint32_t qos)
{
    topics_.emplace_back(topic, qos);
}

[[nodiscard]] const std::vector<std::pair<std::string, uint32_t>> &MqttSubscribeOptions::GetTopics() const
{
    return topics_;
}

[[nodiscard]] char **MqttSubscribeOptions::GetTopicList() const
{
    static std::vector<char *> topicList;
    topicList.clear();
    for (const auto &topic : topics_) {
        topicList.push_back(const_cast<char *>(topic.first.c_str()));
    }
    return topicList.data();
}

[[nodiscard]] int *MqttSubscribeOptions::GetQosList() const
{
    static std::vector<int> qosList;
    qosList.clear();
    for (const auto &topic : topics_) {
        qosList.push_back(static_cast<int>(topic.second));
    }
    return qosList.data();
}
}
} // namespace OHOS::PahoMqtt